package com.jlzj.handler;

import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.List;

/**
 * TODO:
 *
 * @author jiangyangchuan
 * @date 2022/8/14 0014 22:29
 */

public class MyInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        String methodName = method.getName();
        Class returnType = method.getReturnType();
        Class targetClass = method.getDeclaringClass();
        if(!ObjectUtils.isEmpty(targetClass)){
            System.out.println("========被代理的类是:::"+targetClass.getName());
        }
        if(returnType == void.class){
            System.out.println("========被代理的方法"+methodName+"返回类型是void");
        }else if(returnType == List.class){
            System.out.println("========被代理的方法"+methodName+"返回类型是List");
        }else if(returnType == String.class){
            System.out.println("========被代理的方法"+methodName+"返回类型是String");
        }
        //真正的代理逻辑要实现的
        return null;
    }
}
